package com.web.cms.doc.service;

import com.blue.jdbc.JdbcDataSource;
import com.blue.jdbc.Page;
import com.web.cms.doc.dao.DocCommentDao;
import com.web.cms.doc.dao.DocDao;
import com.web.cms.doc.model.DocComment;
import com.web.core.util.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("cmsCommentService")
@Transactional
@JdbcDataSource(Const.DS_CMS)
public class DocCommentService
{
	@Autowired
	private DocCommentDao docCommentDao;
	@Autowired
	private DocDao docDao;
	
	public DocCommentService()
	{
	}
	
	public DocComment save(DocComment comment)
	{
		if (comment.getId() == null)
		{
			docCommentDao.save(comment);
			docDao.inc(comment.getDocId(), "comments", 1);
		}
		else
		{
			docCommentDao.update(comment);
		}
		DocComment c = docCommentDao.get(comment.getId());
		return c;
	}
	
	public DocComment get(Long id)
	{
		DocComment comment = docCommentDao.get(id);
		return comment;
	}
	
	public Page<DocComment> list(DocComment comment, Page<DocComment> page)
	{
		page = docCommentDao.list(comment, page);
		return page;
	}
	
}
